package com.demo49_中序遍历;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<Integer> inorderTraversal(TreeNode root) {
        // 左根右
        ArrayList<Integer> list = new ArrayList<>();
        inOrder(list,root);
        return list;
    }

    private void inOrder(ArrayList<Integer> list, TreeNode root) {
        if (root==null){
            return;
        }
        //访问左节点
        inOrder(list,root.left);
        //访问本结点数据
        list.add(root.val);
        //访问右结点
        inOrder(list,root.right);
    }
}
class TreeNode {
    int val ;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;
    }
}